import java.util.Arrays;

/*
* 数组的排序
* 1.冒泡排序
* 2.希尔排序
* 3.插入排序
* 4.快速排序
* 5.归并排序
* 6.选择排序
* 7.堆排序
*
* */
public class Test3 {
    public static void main(String[] args) {
        int[] array = new int[]{2,3,5,4,8};
        reverse(array);
        System.out.println(Arrays.toString(array));
        Arrays.fill(array,2);//填充
        System.out.println(Arrays.toString(array));
        Arrays.fill(array,1,3,5);
        System.out.println(Arrays.toString(array));//局部填充


    }
/*
* 数组逆序
* */
    public static void reverse(int[] array) {
        int left = 0;
        int right = array.length - 1;
        while(left < right) {
            int tmp = array[left];
            array[left] = array[right];
            array[right] = tmp;
            left++;
            right--;
        }
    }

/*
* 冒泡排序
* */
    public static void bubbleSort(int[] array) {
        boolean flg = false;
        for (int i = 0; i < array.length; i++) {
            for (int j = 0; j < array.length - i - 1; j++) {
                if(array[j] > array[j + 1]) {
                    int tmp = array[j];
                    array[j] = array[j + 1];
                    array[j + 1] = tmp;
                    flg = true;
                }
            }
        }
        if(flg == false) {
            return;
        }
    }
    public static void main1(String[] args) {

        int[] array = new int[]{2,3,5,4,8};
        boolean flg = false;
        for (int i = 0; i < array.length; i++) {
            for (int j = 0; j < array.length - i - 1; j++) {
                if(array[j] > array[j + 1]) {
                    int tmp = array[j];
                    array[j] = array[j + 1];
                    array[j + 1] = tmp;
                    flg = true;
                }
            }
        }
        System.out.println(Arrays.toString(array));
    }
}
